function UserManager()
{
	// no User object because we will manage never more than one user at the time
	var uid = null; // user id
	var name = null; // user name
	var pic = null; // user picture filename
	
	// singleton
	if ( UserManager.prototype._singletonInstance ) {
	      return UserManager.prototype._singletonInstance;
	}
	UserManager.prototype._singletonInstance = this;
	
	// check if the user is logged with Thank Auth
	if(thankAuth())
	{
		console.log('logged with Thank Auth');
	}
	// inialize Facebook API and check if the user is logged with Facebook
	else if(Facebook())
	{
		console.log('logged with Facebook');
		// get basic data
		testAPI();
	}
	else
	{
		$('#connection').show();
		console.log('not logged');
	}
	
	/*
	 * PUBLIC
	 * get data about the user
	 */
	function getUid()
	{
		return uid;
	}
	
	function getPic()
	{
		return pic;
	}
	
	function getName()
	{
		return name;
	}
	
	
	/*
	 * PRIVATE
	 * initialize the Facebook API and get basic data
	 */
	function Facebook()
	{
		// inialize Facebook API
		window.fbAsyncInit = function() {
		    FB.init({
		      appId      : '395207437230562', // App ID
		      channelUrl : BASEPATH+'assets/channel.html', // Channel File
		      status     : true, // check login status
		      cookie     : true, // enable cookies to allow the server to access the session
		      xfbml      : true  // parse XFBML
		    });

		    // Additional init code here
		    
		    	FB.getLoginStatus(function(response) {
			    	  if (response.status === 'connected') {
			    	    // connected
			    		
			    		$('#user').show();
			    		return true;
			    	  }
			    	  else if (response.status === 'not_authorized') {
			    	    // not_authorized
			    		  $('#connection').show();
			    		  return true;
			    	  } else {
			    	    // not_logged_in
			    		  $('#connection').show();
			    		  return false;
			    	  }
			    	 });
		    
		  };

		  // Load the SDK Asynchronously
		  (function(d){
		     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
		     if (d.getElementById(id)) {return;}
		     js = d.createElement('script'); js.id = id; js.async = true;
		     js.src = "//connect.facebook.net/en_US/all.js";
		     ref.parentNode.insertBefore(js, ref);
		   }(document));
		  
		  
		  // prompt the correct login
		  function login() {
			    FB.login(function(response) {
			        if (response.authResponse) {
			            // connected
			        	
			        	// switch login/logout menu
				        $('#user').show();
				        $('#connection').hide();
				        
				        // update user info
				        testAPI();
			        } else {
			            // cancelled
			        }
			    });
			}
		  
		  function logout() {
			    FB.logout(function(response) {
			        console.log('User is now logged out');
			        // switch login/logout menu
			        $('#connection').show();
			        $('#user').hide();
			    });
			}
		  
		  // test API function
		  function testAPI() {
			    console.log('Welcome!  Fetching your information.... ');
			    FB.api('/me', function(response) {
			        console.log('Good to see you, ' + response.name + '.');
			        // get user info
			        uid = response.id;
			    });
			}
	};
	
	function thankAuth()
	{
		// check if the user is logged
		$.ajax({
			type: 'GET',
			url: BASEPATH+'auth/is_logged_in',
			timeout: 3000,
			success: function(data)
			{
				if(data === true)
				{
					return true;
				}
				else
				{
					return false;
				}
			},
	        error: function() { return false; }
		});
	}
}